package cn.tsinghua.comsmacitccntsinghua.bean;

import com.google.gson.Gson;

import lombok.Data;
import lombok.ToString;

@Data
@ToString
public class NormalResponse {
    private boolean result;
    private String msg;
    private String errmsg;
    private Object data;

    public NormalResponse() {
    }

    public NormalResponse(boolean result, String msg) {
        this.result = result;
        this.msg = msg;
        this.errmsg="";
        this.data="";
    }

    public NormalResponse(boolean result, String msg, String errmsg, Object data) {
        this.result = result;
        this.msg = msg;
        this.errmsg = errmsg;
        this.data = data;
    }

    public <T>T parse(Class<T> cls){
        try{
            if(null==this.data)return null;
            T t=new Gson().fromJson(new Gson().toJson(this.data),cls);
            return t;
        }catch (Exception e){

        }
        return null;
    }

}